<?php
if(!defined('DEDEINC'))
{
    exit("Request Error!");
}
/**
 * 商品列表标签
 *
 * @version        $Id: productlist.lib.php 1 2011年4月24日 淘掌门 $
 * @package        DedeCMS.Taglib
 * @copyright      Copyright (c) 2010 - 2011, TaoZhangMen, Inc.
 * @link           http://www.taozhangmen.net
 */
 
/*>>dede>>
<name>商品列表标签</name>
<type>全局标记</type>
<for>V55,V56,V57</for>
<description>用于获取指定类目或者关键词或者指定商品ID列表的商品</description>
<demo>
{dede:productlist cat=16 keyword='女装' ids='' num=5 cache=86400 position='dede_home' fields='num_iid,title,pic_url,item_location,price,commission'}
<a href="[field:detail_link/]">[field:title/]</a>
{/dede}
</demo>
<attributes>
    <iterm>cat:数字，商品类目ID</iterm>
    <iterm>keyword:关键词</iterm>
    <iterm>ids:商品ID</iterm>
    <iterm>num:数字，取的商品数量，最多20条</iterm>
    <iterm>cache:数字，缓存时间，单位秒</iterm>
    <iterm>position:缓存位置</iterm>
    <iterm>fields:取的字段，num_iid必须取，支持的字段num_iid,title,pic_url,item_location,price,commission</iterm>
</attributes>
>>dede>>*/
 
require_once(DEDEROOT.'/pisces/plugin.php');
function lib_productlist(&$ctag,&$refObj)
{
    $attlist="cat|16,num|10,cache|86400,position|dede_home";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    $innertext = trim($ctag->GetInnerText());
    $list = taozhangmen_product_list($cat,$keyword,$num,$cache,$position,$fields);
    $ctp = new DedeTagParse();
    $ctp->SetNameSpace('field','[',']');
    $ctp->LoadSource($innertext);
    foreach($list as $v)
    {
    	foreach($ctp->CTags as $tagid=>$ctag)
	    {
	        if(!empty($v[$ctag->GetName()]))
	        {
	            $ctp->Assign($tagid,$v[$ctag->GetName()]);
	        }
	    }
	    $revalue .= $ctp->GetResult();
    }
    return $revalue;
}